﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using KaoQin.RFIDLIB;
using KaoQin.BLL;

namespace KaoQin.FrmTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnWriteUserData_Click(object sender, EventArgs e)
        {
            CardFun bll = new CardFun();
            try
            {
                int state = 0;
                string input = "ABCDEFGHIJKLM我们都是中国人，对吗";
                state=bll.WriteUserDatas(string.Empty, input);
                bll.DoBeed(50);
                if (state == 0)
                {
                    MessageBox.Show("数据写入成功");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                bll.Dispose();
            }
        }

        private void btnReadUserData_Click(object sender, EventArgs e)
        {
            CardFun bll = new CardFun();
            try
            {
                string outdata;
                bll.GetUserDatas(string.Empty, out outdata);
                bll.DoBeed(50);
                MessageBox.Show("读取用户数据成功:"+outdata);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                bll.Dispose();
            }
        }

        private void btnWritesysData_Click(object sender, EventArgs e)
        {
            CardFun bll = new CardFun();
            try
            {
                int state = 0;
                string input = "ABCDEFGHIJKLM系统区数据";
                state = bll.WriteSysDatas(string.Empty, input);
                bll.DoBeed(50);
                if (state == 0)
                {
                    MessageBox.Show("数据写入成功");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                bll.Dispose();
            }
        }

        private void btnReadsysData_Click(object sender, EventArgs e)
        {
            CardFun bll = new CardFun();
            try
            {
                string outdata;
                bll.GetSysDatas(string.Empty, out outdata);
                bll.DoBeed(50);
                MessageBox.Show("读取系统数据成功："+outdata);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                bll.Dispose();
            }
        }

        private void btnChangePass_Click(object sender, EventArgs e)
        {
            CardFun bll = new CardFun();
            try
            {

                if (bll.ChangePass(string.Empty, string.Empty) == 0)
                {
                    bll.DoBeed(50);
                    MessageBox.Show("修改密码成功");
                }
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                bll.Dispose();
            }
        }

        private void btngetserial_Click(object sender, EventArgs e)
        {
            CardFun bll = new CardFun();
            int state;
            try
            {
                string outdata;
                state = bll.GetCardSerial(out outdata);
                if ( state== 0)
                {
                    bll.DoBeed(50);
                    MessageBox.Show("获取卡序列号成功："+outdata);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                bll.Dispose();
            }
        }

        private void btnWriteUniqueID_Click(object sender, EventArgs e)
        {
            CardFun bll = new CardFun();
            try
            {
                
                if (bll.WriteCardUniqueID(string.Empty,Guid.NewGuid()) == 0)
                {
                    bll.DoBeed(50);
                    MessageBox.Show("写入唯一ID成功");
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                bll.Dispose();
            }
        }

        private void btnReadUniqueID_Click(object sender, EventArgs e)
        {
            CardFun bll = new CardFun();
            try
            {
                Guid outdata;
                if (bll.GetCardUniqueID(string.Empty,out outdata) == 0)
                {
                    bll.DoBeed(50);
                    MessageBox.Show("获取UNIQUEID成功：" + outdata.ToString());
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                bll.Dispose();
            }
        }

        private void btntestSqlite_Click(object sender, EventArgs e)
        {
            try
            {
                BLL.SwipeCardRecord bll = new SwipeCardRecord();

                int count = bll.GetRecordCount(" CreateTime>='2012-10-31' and CreateTime<'2012-11-1'");

                MessageBox.Show(count.ToString());
            }
            catch (Exception ex)
            {
                
                throw;
            }
        }
    }
}
